package com.zyark.web.controller;

import com.zyark.domain.VisitorInfo;
import com.zyark.service.VisitorInfoService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * Created by ron on 17-9-2.
 */
@Controller
@RequestMapping(value = "api/v1/anon")
public class ClinetVisitorController {
    @Resource
    VisitorInfoService visitorInfoService;

    @RequestMapping(value = "visitor",method = RequestMethod.POST)
    @ResponseBody
    public Object saveVisitor(@RequestBody VisitorInfo visitorInfo){
        VisitorInfo infoForSearch = new VisitorInfo();
        infoForSearch.setContract(visitorInfo.getContract());
        List<VisitorInfo> visitorInfoList = visitorInfoService.selectByEntityWithSimpleResult(infoForSearch,null,null);
        if (visitorInfoList.size()==0) {
            visitorInfo.setCreateTime(new Date());
            return visitorInfoService.saveSelective(visitorInfo);
        }else {
            return 0;
        }
    }
}
